package com.example.ioc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

// 启动类
@SpringBootApplication
public class IocApplication {

    public static void main(String[] args) {
        // 这条代码帮我们返回了一个容器
        // Spring上下文
        // 从context中获取bean
        ApplicationContext context = SpringApplication.run(IocApplication.class, args);
//        UserController bean = context.getBean(UserController.class);
//        bean.doController();

////        // 1.根据类名来获取bean
////        UserService bean1 = context.getBean(UserService.class);
////        bean1.doService();
////        // 2. 根据名称来获取bean,名称是类名,但是是使用小驼峰的方式来命名
////        // 要进行类型的转换,因为getBean是Object类型的
////        UserService bean2 = (UserService) context.getBean("userService");
////        bean2.doService();
////
////        UService uService = (UService) context.getBean("UService");
////        uService.doUService();
////
////
////        // 3. 根据名称和类名拿到bean,可能根据类名拿到多个对象
////        UserService userServiece = context.getBean("userService", UserService.class);
////        userServiece.doService();
////
////        // Repository
////        UserRepository repository = context.getBean(UserRepository.class);
////        repository.doRepository();
////
////        // Component
////        UserComponent userComponent = context.getBean(UserComponent.class);
////        userComponent.doComponent();
////
////        // Configuration
////        UserConfig userConfig = context.getBean(UserConfig.class);
////        userConfig.doConfiguration();
////
////        // @Bean演示
////        UserInfo userInfo = (UserInfo) context.getBean("userInfo");
////        System.out.println(userInfo);
////
////        UserInfo userInfo1 = context.getBean("userInfo",UserInfo.class);
////        System.out.println(userInfo1);
    }
}

